import type { UserProfile } from '~/types/user';

/* 用户的仓库 */
const useUserStore = defineStore('user', {
  persist: {
    storage: persistedState.localStorage
  },
  state: () => {
    return {
      token: '' as string,
      days: '' as string,
      userInfo: {} as const as UserProfile
    };
  },
  actions: {
    /**
     * 存储token，因为网易那边传回来的cookie过于巨大
     * 因此只能存在local storage中
     * @param storage token string
     */
    setToken(storage: string): void {
      this.token = storage;
    },
    setDays(days: string) {
      this.days = days;
    },
    setUserInfo(data: UserProfile) {
      this.userInfo = data;
    }
  }
});

export default useUserStore;
